
//缩放居中效果
function scaleToWindow(canvas, vertical) {
  var scaleX, scaleY, scale;

  var html = document.documentElement;

  //1. Scale the canvas to the correct size
  //Figure out the scale amount on each axis
  scaleX = html.clientWidth / canvas.offsetWidth;
  scaleY = html.clientHeight / canvas.offsetHeight;

  //Scale the canvas based on whichever value is less: `scaleX` or `scaleY`
  scale = Math.min(scaleX, scaleY);
  canvas.style.transformOrigin = "50% 50%";
  canvas.style.transform = "scale(" + scale + ")";

  vertical = vertical || 'middle';

  if(vertical == 'top'){
    canvas.style.marginTop = (canvas.offsetHeight*scale - canvas.offsetHeight)/2  + 'px'
  }else if(vertical == 'middle'){
    canvas.style.marginTop = (html.clientHeight - canvas.offsetHeight)/2 + "px";
  }else if(vertical == 'bottom'){
    canvas.style.marginTop = (html.clientHeight - canvas.offsetHeight - (canvas.offsetHeight*scale - canvas.offsetHeight)/2) + 'px'
  }

  canvas.style.marginLeft = (html.clientWidth - canvas.offsetWidth) /2 + "px";

  canvas.style.paddingLeft = 0 + "px";
  canvas.style.paddingRight = 0 + "px";
  canvas.style.paddingTop = 0 + "px";
  canvas.style.paddingBottom = 0 + "px";
  canvas.style.display = "block";
  // canvas.style.position = "static";

  return scale;
}